Repository navigation
feat(mcp): forward hooks_timeout on laya_route_batch - #770
Merged
NandhaKishorM merged 1 commit intoOct 1, 2026
Merged
Conversation
Router.route_batch takes hooks_timeout (router.py:911, docstring 925-926) and applies it per-request during on_route dispatch. The batch sibling laya_predict_batch has always had the override plumbed; laya_route_batch did not. The tool layer accepted only `requests`, so an operator running a routing sweep over a workload cannot protect against a slow or hung operator hook the way they can on the predict path. - New optional `hooks_timeout` arg on laya_route_batch; forwarded to Router.route_batch only when the caller actually asked for one, so a pre-NandhaKishorM#577 attached Router keeps working. - _validate_hooks_timeout wraps core's validate_timeout and turns its ValueError into a ToolError code (`invalid_hooks_timeout`) at the MCP boundary. Bools rejected here (not by core, which coerces True -> 1.0). - Server wrapper exposes hooks_timeout; the tool description now mentions it so clients discover the knob. - Tests: BatchRouter.route_batch records the timeout; six new checks cover forwarding (float + coerced int), default-stays-unset, validation errors, and a strict-signature Router stub as the witness against always-kwarg. Four mutations each produce a named FAIL.
4 tasks done
Owner
|
Merged for 0.3.23. Verified on the integrated branch, not on the PR in isolation: every suite in the Thank you. |
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
laya_route_batchnow accepts and forwardshooks_timeout, matching what its batch siblinglaya_predict_batchdoes and whatRouter.route_batchhas always taken.Why
Router.route_batchgrows ahooks_timeoutparameter (laya/router.py:911, docstring:925-926) that overrides the Router's own deadline for every request'son_routedispatch. The single-requestlaya_routehas a route-only path; the batch tool never exposed it, so a caller sweeping routing decisions over a workload cannot protect against a slow or hung operator hook in the same way they can on the predict path.Concretely: an operator has an
on_routehook that does an outbound check. On a bad network, the Router's configured deadline is, say, 2 s; a caller running a 500-requestlaya_route_batchto inspect a workload's routing before paying load cost gets stuck at 2 s × N with no way to say "give me the aggregate faster, use 200 ms."laya_predict_batchcan already do this;laya_route_batchcould not.How it was verified
Four mutations were run against
laya/mcp/tools.py; each produced a named FAIL on the restored tree, not a crash:route_batch(items)(never forwards)batch/route_hooks_timeout_forwarded,batch/route_hooks_timeout_int_coercedhooks_timeouteven when Nonebatch/route_strict_router_no_kwargboolaccepted by falling through to core'svalidate_timeoutbatch/route_bad_hooks_timeout_True(plus 4 code-name checks)batch/route_bad_hooks_timeout_*— ValueError / TypeError surface raw, not asinvalid_hooks_timeoutDesign notes
_validate_hooks_timeoutwraps core'slaya.hooks.validate_timeoutand turns itsValueErrorinto aToolError("invalid_hooks_timeout", ...), so an MCP caller gets a real code back instead ofinternal_error: ValueError.validate_timeout(True)silently coerces to1.0and gives a caller a one-second deadline they did not ask for — the same pattern_validate_batch_sizeguards.hooks_timeoutis forwarded only when the caller set one, so a pre-feat(agent): per-call prediction hooks on predict_long, and no window for a skipped answer #577 attached Router (or a stub) still accepts the call. TheStrictRouteRouterfixture is the witness for this; without it, the always-forward mutation would pass the suite.Checklist
mainlaya/mcp/server.py)Fixes #